home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / ISFILE.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  914b  |  39 lines

  1. /*
  2. **  ISFILE.C - determine if a file handle is associated with a file
  3. **
  4. **  by: Bob Jarvis
  5. **
  6. **    Returns:    1 - handle is associated with a file
  7. **                0 - handle is associated with a device
  8. **               -1 - error
  9. */
  10.  
  11. #include <dos.h>
  12.  
  13. int isfile(int handle)
  14. {
  15.         union REGS regs;
  16.  
  17.         regs.x.ax = 0x4400;
  18.         regs.x.bx = handle;
  19.  
  20.         intdos(®s, ®s);
  21.  
  22.         if(regs.x.cflag == 0)                   /* carry flag not set */
  23.         {
  24.                 if((regs.x.dx & 0x80) == 0)
  25.                         return 1;
  26.                 else    return 0;
  27.         }
  28.         else    return -1;                      /* error - return -1  */
  29. }
  30.  
  31. #include <stdio.h>
  32.  
  33. int main()
  34. {
  35.         if(isfile(fileno(stdout)))
  36.                 printf("stdout is associated with a file\n");
  37.         else    printf("stdout is NOT associated with a file\n");
  38. }
  39.